What are your visitors doing on your site?Logging system that lets you keep track of what your visitors are doing ( or not doing ) at your site |
|
Current version:
n/a
Written by: ASPCode.net
Submitted date: 2000-03-02 |
|
|
So, you have spent X hours( or days ) implementing a certain
function ( lets say a recommend script ) at your website. You upload it,
test it and
see it's working. You feel great, don't you? Now, I bet, just the very
next day, you are very curious to see if it became the success you really
thought it would be. Now, how do you measure it?
What I will give you here is some simple ( so simple it's nearly
embarassing... ) functions
you can use to log just anything you'd like: How many visitors have used
the recommend service and which pages got recommended, how many have
clicked on a certain button - you name it.
First we will need a database, let's use an Access database for simplicity.
Create a table called LOGACTION and add four columns:
- id AutoNumber
- actionid text(50)
- description text(255)
- when datetime
The id is just an autonumbering field.
actionid will be used as an category specifier. Like 'recommend' or
'buttonclick'
description will be used as a more descriptive text, you could for example
add the actual page where the action took place ( using HTTP_REFERER ) or
whoch specific page was recommended etc
when is of course a timestamp
Next, create a file called logaction.asp
Edit it like this:
<%
Public Sub LogAction ( sCategory, sText )
Dim oConn
Dim oRS
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "change-to-point-to-your-database"
Set oRS = Server.CreateObject("ADODB.Recordset")
oRS.Open "select * from logaction where id=-1 " ,oConn ,1,3
oRS.AddNew
oRS("actionid") = sCategory
oRS("description") = sText
oRS("when") = Now()
oRS.Update
oRS.Close
oConn.Close
End Sub
%>
Now, all you have to do is include the file
and call LogAction, for example in a sendmail.asp which is used for site
recommendation:
****
LogAction "recommend", sThePage
***
Reporting function: How can we see what actions has took place?
Create a file called view.asp and edit it like this:
Action viewer
| Category |
Text |
When |
<%
Dim oConn
Dim oRS
Dim strSort
strSort = "when"
If Request.QueryString("sort") <> "" Then
strSort = Request.QueryString("sort")
End If
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "change-to-point-to-your-database"
Set oRS = oConn.Execute("select * from logaction order by " & strSort )
While Not oRS.EOF
%>
| <%=oRS("actionid")%> |
<%=oRS("description")%> |
<%=oRS("when")%> |
<%
oRS.MoveNext
Wend
%>
Now we have a simple report function which you also let you sort by date,
action etc.
|
|